#include <iostream>
#include <cmath>

using namespace std;

class GetSubset
{
private:
	int* entireSet;
	int _size;

	void recursivePrint(int* arr, int level, bool* flag);
	void iterativePrint(int* arr, bool* flag);
public:
	GetSubset();
	void getSet(int s[], int size);
	void printSubset();
};

GetSubset::GetSubset(){ entireSet = NULL; }

void GetSubset::getSet(int s[], int size){ entireSet = s; _size = size;}

void GetSubset::printSubset()
{
	
	bool* flag = new bool[_size];
	for (int i = 0; i < _size; i++) flag[i] = false;
	/*
	recursivePrint(entireSet, 0, flag);
	*/
	iterativePrint(entireSet, flag);
}

void GetSubset::recursivePrint(int* arr, int level, bool* flag)
{
	if (level >= _size){
		for (int i = 0; i < _size; i++){
			if (flag[i])
				cout <<arr[i] <<" ";
		}
		cout <<endl;
		return;
	}

	flag[level] = true;
	recursivePrint(arr, level + 1, flag);
	flag[level] = false;
	recursivePrint(arr, level + 1, flag);
}

void GetSubset::iterativePrint(int* arr, bool* flag)
{
	int limit = pow(2, (double)_size) - 1;
	for (int i = 0; i <= limit; i++){
		int j = 0 , now = i;
		for (j = 0; j < _size; j++){
			flag[j] = false;
		}
		for (j = 0; j < _size; j++){
			if (now & 1)
				cout <<arr[j] <<" ";
			now = now>>1;
		}
		cout <<endl;
	}
}

int getSubsetsTest()
{
	int testData[] = {1, 2, 3, 4};
	GetSubset subsetCreater;
	subsetCreater.getSet(testData, sizeof(testData) / sizeof(int));
	subsetCreater.printSubset();

	cin.get();
	return 0;
}